﻿/**
 * Example Document Class - just a basic framework for this class
 *
 * The main document class for an MVC app, define as the document class for your fla
 *
 * @author  	robert turrall
 * @date	   	31.12.2008
 * @license: 	This particular file may be used freely. It serves simply as an example.
 * 				Of course, a credit is always nice ;-)
 *
 * @version	1.0
 */
package {

	// please note that it's not really good practice to use the default package (i.e. none). 
	// You should normally save your classes in a package which corresponds to your application
	
	import net.turrall.mvc.*;
	//import your other package classes as required here
	import flash.display.MovieClip;    
	import flash.display.DisplayObject;
	
	public class Example extends MovieClip {			
		
		private var _className:String;
		
		// MVC classes
		public var _model:ExampleModel; 				// YOUR Model class, a subclass of AbstractModel
		private var _view:ExampleView;					// YOUR View class, a subclass of AbstractView
		private var _controller:ExampleController;		// YOUR Controller class, a subclass of AbstractController
		
		
		/**
		 * Example Constructor
		 *
		 * @param   target   The movie clip to which the view is attached.
		 */
		public function Example() {
		
			_className = "Example";
			
			// instantiate MVC classes
			// model
			_model = new ExampleModel();
			// controller
			_controller = new ExampleController(_model);
			// view
			_view = new ExampleView(_model, _controller, this);
			
			
			// add event listeners for the view to get it's updates from the model
			_model.addEventListener(AbstractModel.UPDATE,_view.update);
			_model.addEventListener(ExampleModel.MODEL_INITIALISE,_view.update);
			_model.addEventListener(ExampleModel.MODEL_INITERROR,_view.update);
		}					
	}
}
